<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
    <a-form :form="form">
        <a-row>
          <a-col :xs="24" :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="收款单位">
              <a-input
                placeholder="请输入收款单位"
                v-decorator="['name', { rules: [{ required: true, message: '请输入收款单位' }] }]"
              />
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="统一社会信用代码">
              <a-input
                placeholder="请输入统一社会信用代码"
                v-decorator="['uscc', { rules: [{ required: false, message: '请输入统一社会信用代码' }] }]"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :xs="24" :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="开户银行账号">
              <a-input
                placeholder="请输入开户银行账号"
                v-decorator="['bankAccount', { rules: [{ required: false, message: '请输入开户银行账号' }] }]"
              />
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="开户银行名称">
              <a-input
                placeholder="请输入开户银行名称"
                v-decorator="['bankName', { rules: [{ required: false, message: '请输入开户银行名称' }] }]"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :xs="24" :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="联系人手机">
              <a-input
                placeholder="请输入联系人手机"
                v-decorator="['contactPhone', { rules: [{ required: false, message: '请输入联系人手机' }] }]"
              />
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="联系人姓名">
              <a-input
                placeholder="请输入联系人姓名"
                v-decorator="['contactPerson', { rules: [{ required: false, message: '请输入联系人姓名' }] }]"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :xs="24" :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="电子邮件">
              <a-input
                placeholder="请输入电子邮件"
                v-decorator="['email', { rules: [{ required: false, message: '请输入电子邮件' }] }]"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import pick from 'lodash.pick'
import moment from 'moment'

export default {
  name: 'PayeeModel',
  data() {
    return {
      title: '交易信息',
      visible: false,
      model: {},
      saleSource: [],
      SaleInfosLike: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },

      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: '/sale/cxmSaleRelatedEnterprise/addRelatedEterprise',
        edit: '/sale/cxmSaleRelatedEnterprise/editRelatedEnterprise',
      },
      showDing: false,
      showEnterpriseUscc: false,
    }
  },
  created() {
  },
  methods: {
    changeDepositNotes(val) {
      if (val == '不可退') {
        this.showDing = true
      } else {
        this.showDing = false
      }
    },
    add() {
      const that = this;
      that.edit({})
    },
    edit(record) {
      console.log(record);
      this.form.resetFields()
      this.model = Object.assign({}, record)
      console.log(this.model);
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue({
          name:this.model.name,
          uscc:this.model.uscc,
          bankAccount:this.model.bankAccount,
          bankName:this.model.bankName,
          contactPhone:this.model.contactPhone,
          email:this.model.email,
          contactPerson:this.model.contactPerson,
/*           createUser:this.model.createUser,
          createTime:this.model.createTime?moment(this.model.createTime):null, */
        })
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {

        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'post'
          }
          let formData = Object.assign(this.model, values,{enterpriseType:4})
          //时间格式化
          /* formData.createTime = formData.createTime ? formData.createTime.format('YYYY-MM-DD HH:mm:ss') : null */

          httpAction(httpurl, formData, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style lang="less" scoped>
</style>